package com.bdqn.t350.servlet.pet;

import com.bdqn.t350.entity.Pet;
import com.bdqn.t350.service.PetService;
import com.bdqn.t350.service.PetServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UpdatePetSexServlet", urlPatterns = "/UpdatePetSexServlet")
public class UpdatePetSexServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sex = req.getParameter("sex");
        String id = req.getParameter("id");
        PetService petService = new PetServiceImp();

        if (sex.equals("雄")) {
            sex = "雌";
        } else if (sex.equals("雌")) {
            sex = "雄";
        }

        Pet pet = new Pet();
        pet.setPetId(Integer.parseInt(id));
        pet.setPetSex(sex);
        int count = petService.updateBySexBiz(pet);
        resp.getWriter().print(count);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
